<template>
  <div>
    <el-row class="tac">
      <el-col :span="24">
        <!-- router el-menu的属性 可以开启路由跳转 以index作为url -->
        <el-menu
          default-active="2"
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          router
        >
          <el-submenu
            v-for="(menu, index) in menuList"
            :key="index"
            :index="index + '1'"
          >
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{ menu.title }}</span>
            </template>
            <el-menu-item-group>
              <el-menu-item
                v-for="(subMenu, num) in menu.children"
                :key="num + 'sub'"
                :index="subMenu.url"
              >
                {{ subMenu.title }}</el-menu-item
              >
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      menuList: [],
    };
  },
  computed: {
    // ...mapGetters(['menuList'])
  },
  created() {
    // 这里不再发请求了，应该用vuex中的数据 通过getter获取userinfo中的url 放在这里
    // console.log(this.$store.getters.menuList); // 用这里的数据 后面不发请求了
    // this.menuList = this.$store.getters.menuList;
    this.getMenuList();
  },
  methods: {
    getMenuList() {
      this.http("/menulist", {
        params: {
          istree: 1,
        },
      }).then((res) => {
        this.menuList = res.list;
      });
    },
  },
};
</script>

<style>
</style>